package entity;

public class BaseTank extends Tank {

	private static final long serialVersionUID = -7801315281726518633L;
	private Bullet[] bullets;
	private int initBulletNumber;
	
	private boolean isEmptyBullet = true;
	private int tempBulletIndex;
	private MoveSpeed BulletSpeed;
	
	private void init() {
	}
	
	public BaseTank(int number) {
		this.initBulletNumber = number;
	}
	
	public void shoot() {
		if(isEmptyBullet) {
			this.initBullet();
			isEmptyBullet = false;
		}
		if(tempBulletIndex>initBulletNumber) {
			isEmptyBullet = true;
			return;
		}
		Bullet bt = null;
		if((bt = bullets[tempBulletIndex])!=null) {
			ShootGenerator.shoot(this,bt, this.getDirection());
		}
		tempBulletIndex++;
		
	}

	public void start() {
		this.init();
	}

	public void dead() {
		this.setAlive(false);
	}

	public void initBullet() {
		if(bullets==null) {
			bullets = new Bullet[initBulletNumber];
		} 
		for(int i=0;i<bullets.length;i++) {
			if(bullets[i] != null && !bullets[i].isUsed()) {
				continue;
			}
			bullets[i] = new Bullet(this.getCurrentPosition());
		}
		tempBulletIndex = 0 ;
	}

	public MoveSpeed getBulletSpeed() {
		return BulletSpeed;
	}

	public void setBulletSpeed(MoveSpeed bulletSpeed) {
		BulletSpeed = bulletSpeed;
	}
	

}
